#!/usr/bin/env bash

set -euo pipefail

source env_vars.sh

COMPOSE_FILE_PATH="integration_tests/${INTEGRATION_TEST_CASE}/docker-compose.yml"

if [ $BUILDKITE_COMMAND_EXIT_STATUS -ne 0 ]; then

  if docker-compose -f "$COMPOSE_FILE_PATH" ps | grep "risingwave-standalone" > /dev/null; then
      echo "--- upload risingwave standalone docker compose logs"
      docker-compose -f "$COMPOSE_FILE_PATH" logs risingwave-standalone > risingwave-standalone.log
  else
      echo "--- upload risingwave docker compose logs"
      docker-compose -f "$COMPOSE_FILE_PATH" logs compactor-0 > risingwave-compactor.log
      docker-compose -f "$COMPOSE_FILE_PATH" logs compute-node-0 > risingwave-compute.log
      docker-compose -f "$COMPOSE_FILE_PATH" logs frontend-node-0 > risingwave-frontend.log
      docker-compose -f "$COMPOSE_FILE_PATH" logs meta-node-0 > risingwave-meta.log
  fi
    buildkite-agent artifact upload "./risingwave-*.log"
fi